import { ref, reactive, computed } from 'vue'
import { defineStore } from 'pinia'
import { getStorage, setStorage, removeStorage } from '@/utils/storage';

export const useUserStore = defineStore('user', () => {
  const userInfo = getStorage('user') ?? ''
  const user = ref(userInfo)

  const setUser = data => {
    user.value = data
    setStorage('user', data)
  }

  const clearUser = data => {
    user.value = ''
    removeStorage('user')
  }

  return { user, setUser, clearUser }
})
